﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HZ.Supervise.Web.Secondphase
{
    public partial class SelectCompanyToBlackList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
        }

        void BindList()
        {
            int t = 0;
            HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
            System.Data.DataTable dt = new System.Data.DataTable();
            string _values = HZ.Fun.CheckString(this.txtName.Text);

            dt = pre.GetCompanyNotInBlackList(_values, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            AspNetPager1.RecordCount = t;
            gvwCompany.DataSource = dt;
            gvwCompany.DataBind();
        }
        /// <summary>
        /// 添加所选企业到黑名单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string companyName = Request.Params["chkCompany"].ToString();
            string[] companyNames = companyName.Split(',');
            foreach (string item in companyNames)
            {
                HZ.Supervise.Model.BlackList blackList = new HZ.Supervise.Model.BlackList();
                
                int t = 0;
                HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
                System.Data.DataTable dt = new System.Data.DataTable();
                string _values = HZ.Fun.CheckString(item);
                dt = pre.GetCompanyInfo(_values, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
                blackList.AddReason = txtReason.Text.Trim();
                blackList.Address = dt.Rows[0]["Address"].ToString();
                blackList.AddTime = DateTime.Now.ToShortDateString();
                blackList.CompanyID = dt.Rows[0]["CompanyID"].ToString();
                blackList.CompanyName = dt.Rows[0]["CompanyName"].ToString();
                blackList.ContactPerson = dt.Rows[0]["ContactPerson"].ToString();
                blackList.Email = dt.Rows[0]["Email"].ToString();
                blackList.Fax = dt.Rows[0]["Fax"].ToString();
                blackList.LayMan = dt.Rows[0]["LayMan"].ToString();
                blackList.TelNo = dt.Rows[0]["TelNo"].ToString();
                
                pre.InsertIntoBlackList(blackList);
            }	
            HZ.Web.WebUtil.Alert("添加到黑名单成功！");
            HZ.Web.WebUtil.ClosePage();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindList();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindList();
        }
    }
}
